/**用户输入验证**/
function CustomerValidate(id) {
    var list = $("#" + id + " .CustomerValidate");
    var result = true;
    var msg = "";
    for (var i = list.length - 1; i >= 0; i--) {
        var type = $(list[i]).attr("ValidateType").split(',');
        for (var j = 0; j < type.length; j++) {
            var typeResult = true;
            switch (type[j]) {
                case "required":
                    var match = /^[^\$%\^&*~/\']*$/;
                    if ($.trim($(list[i]).val()) == "" || !match.test($(list[i]).val())) {
                        msg = "必填项不能为空，不能输入非法字符：$%^&*~/\'！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "mobile":
                    var match = /^(1[0-9]{10})$/;
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "请填写正确格式的手机号！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "phone":
                    var match = /^(\d{3}-\d{7,8}|\d{4}-\d{7,8})$/;
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "电话格式应为“0123-8765432”或者“012-8765432”！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "phoneormobile":
                    var match1 = /^(1[0-9]{10})$/;
                    var match2 = /^(\d{3}-\d{7,8}|\d{4}-\d{7,8})$/;
                    var controlval = $(list[i]).val();
                    if (!match1.test($.trim(controlval)) && !match2.test($.trim(controlval)) && controlval != "") {
                        msg = "请输入手机号或固定电话，电话格式应为“0123-8765432”或者“012-8765432”！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "number":
                    var match = "^\\d{1,8}(\\.\\d{1," + digits + "})?$";
                    if (!$.trim($(list[i]).val()).match(match) && $(list[i]).val() != "") {
                        msg = "请输入非负数，最多" + digits + "位小数，8位整数！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "number2":
                    var match = "^-{0,1}\\d{1,8}(\\.\\d{1," + digits + "})?$";
                    if (!$.trim($(list[i]).val()).match(match) && $(list[i]).val() != "") {
                        msg = "请输入数字，最多" + digits + "位小数，8位整数！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "int":
                    var match = /^[0-9]+$/;
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "请输入整数！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "Banknumber":
                    var match = /^\d+$/g; //
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "卡号格式错误，应该是纯数字！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "FinanceItemNo":
                    var match = /^\d{2}D\d+$/g; //
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "格式错误，请参考正确示例：10D100001！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "Identity":
                    var match = /^\d{18}$/g; //
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "格式错误，请输入18位身份证号！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "AcntName":
                    var match = /^[a-zA-Z][0-9a-zA-Z]{3,14}$/;
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "账户名称以字母开头,4-15位数字、字母组合！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "Email":
                    var match = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                    if (!match.test($.trim($(list[i]).val())) && $(list[i]).val() != "") {
                        msg = "邮箱格式不正确！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
                case "URL":
                    var match = /^[^\$%\^&*~\']*$/;
                    if ($.trim($(list[i]).val()) == "" || !match.test($(list[i]).val())) {
                        msg = "请输入正确的url！";
                        $(list[i]).focus();
                        $(list[i]).addClass("warn");
                        result = false;
                        typeResult = false;
                    } else {
                        $(list[i]).removeClass("warn");
                    }
                    break;
            }
            if (!typeResult) {
                break;
            }
        }
    }
    if (!result) {
        Msgfade(msg);
    }
    return result;
}
/**消息提示弹窗**/
function Msgfade(msg) {
    $.messager.show({
        title: '提示',
        msg: msg,
        timeout: 2000,
        showType: 'fade',
        style: {
            right: '',
            bottom: ''
        }
    });
}
/**根据权限生成页面操作菜单按钮**/
function LinFunc(path,divObj,linkText,onClick,icon,plain,funcId,type) {
    var aHtml = "";
    $.ajax({
        type:"post",
        url:path+"/judgePermiss",
        data:JSON.stringify({
            'funcId':funcId,
            'linkText':linkText,
            'onClick':onClick,
            'icon':icon,
            'plain':plain,
            'type':type
        }),
        dataType:"json",
        async:false,
        contentType:"application/json",
        success:function (data) {
            divObj.append(data);
        }
    });
}
//将页面上的搜索条件的值复制到更多搜索条件弹出框中
function CopyVal(id1, id2) {
    var inputs1 = $("#" + id1 + " input");
    var inputs2 = $("#" + id2 + " input");
    var select1 = $("#" + id1 + " select");
    var select2 = $("#" + id2 + " select");
    for (var i = 0; i < inputs1.length; i++) {
        for (var j = 0; j < inputs2.length; j++) {
            if ($(inputs1[i]).attr("name") == $(inputs2[j]).attr("name") && $(inputs1[i]).attr("name") != undefined) {
                $(inputs2[j]).val($(inputs1[i]).val());
            }
        }
    }
    for (var i = 0; i < select1.length; i++) {
        for (var j = 0; j < select2.length; j++) {
            if ($(select1[i]).attr("name") == $(select2[j]).attr("name")) {
                $(select2[j]).val($(select1[i]).val());
            }
        }
    }
}
